//  ========== 
//  = 宾和   登录业务JS = 
//  ==========
var BpMember;
var ws = null;
var Main = function() {
	mui('.mui-scroll-wrapper').scroll();
	mui.init({
		swipeBack: false //启用右滑关闭功能
	});
	this.init();
	this.even();
	this.loadData();
};
Main.prototype = {
	init: function() {},
	even: function() {
		/**导航菜单*/
		$("#menu").on('tap', function() {
			mui('.mui-off-canvas-wrap').offCanvas().toggle();
		});
		$(".menu-li").on('tap', function(e) {
			var index = $(this).index();
			switch(index) {
				case 1:
					mui.openWindow("user.html", 'user');
					if(!isH5) {
						ws = plus.webview.currentWebview();
						ws.reload(true);
					}
					break;
				case 2:
					openFinanceListTab('financeList.html?index=1', 'financeList', 1);
					break;
				case 3:
					openFinanceListTab('financeList.html?index=0', 'financeList', 0);
					break;
				default:
					break;
			}
		});
		/**跳转账户安全页面*/
		$("#btn-toUserAccount").on('tap', function() {
			if(!BpMember) {
				Util.toast('正在加载数据，请稍等');
				return false;
			}
			mui.openWindow(UrlHelper.customUrl(UrlHelper.urlEncode(BpMember), "userAccount.html"));
		});
		/**跳转我的邀请页面*/
		$('#btn-recommend').on('tap', function() {
			mui.openWindow('userRecommend.html');
		});
		/**点点安盈、点点专享等页面调整*/
		mui('.m-personal-link').on('tap', 'a', function() {
			var href = this.getAttribute('href');
			if(href != '') {
				mui.openWindow(href, href);
			} else {
				return false;
			}
		})
		/**判断是否开通第三方账户*/
		function toAccountHtml(url, vid) {
			if(BpMember.thirdPayFlagId) {
				mui.openWindow(url, vid);
			} else {
				mui.confirm("未完成实名认证：请到个人账户，开通实名认证。", "实名认证", ["取消", "去开通"], function(e) {
					if(e.index == 1) {
						mui.openWindow('registerAccount.html', 'registerAccount');
					}
				})
			}
		}
		/**跳转第三方提现*/
		$("#btn-toWithdraw").on('tap', function() {
			if(!BpMember) {
				Util.toast('正在加载数据，请稍等');
				return false;
			}
			toAccountHtml("withdraw.html?balance=" + BpMember.availableInvestMoney, 'withdraw');
		});
		/**跳转第三方充值*/
		$("#btn-toRecharge").on('tap', function() {
			if(!BpMember) {
				Util.toast('正在加载数据，请稍等');
				return false;
			}
			toAccountHtml("recharge.html?balance=" + BpMember.availableInvestMoney, 'recharge');
		});
		$(".personal-banner-tp").on('tap', function() {
			mui.openWindow("myFundList.html");
		})
	},
	_ajaxGetResult: function(url, param, target) { //ajax获取投标中、回款中、完成、失败笔数
		$.getJSON(url, param, function(retData) {
			target.html(Util.safeString(retData.result, 0));
		})
	},
	loadData: function() {
		if(!Util.checkLoginRedirect()) {
			return false;
		}
		var memberId = storage.getItem("memberId");
		var options = {
			useEasing: true,
			useGrouping: true,
			separator: '',
			decimal: '.',
			prefix: '',
			suffix: '',
			separator: ''
		};
		//获取用户资金信息
		var param = {
			isMobile: isMobile,
			memberId: memberId
		}
		var getAcountInfoUrl = server_url + "/user/mobileaccountBpCustMember.do";
		$.getJSON(getAcountInfoUrl, param, function(retData) {
			var totalAmount = new CountUp("totalAmount", 0.00, (retData.money + retData.money3 + retData.money1 - retData.money5), 2, 1, options);
			totalAmount.start();
			var totalEarnings = new CountUp("totalEarnings", 0.00, retData.money12, 2, 1, options);
			totalEarnings.start();
			var balance = new CountUp("balance", 0.00, retData.money, 2, 1, options);
			balance.start();
		});
		//获取用户基本信息
		var getMemberUrl = server_url + "/user/getBpCustMember.do";
		var getMemberParam = {
			"isMobile": isMobile,
			"memberId": storage.memberId
		}
		$.getJSON(getMemberUrl, getMemberParam, function(retData) {
			if(retData.success) {
				BpMember = retData.data;
				var score = new CountUp("score", 0, (!BpMember.score ? 0 : BpMember.score), 0, 1);
				score.start();
			}
		});

		//var _this = this;
		//_this._ajaxGetResult(server_url + '/user/getCountBidLoanBpCustMember.do', {
		//	memberId: memberId
		//}, $(".m-repayment-bid")); //投标中
		//_this._ajaxGetResult(server_url + '/user/getCountRepaymentLoanBpCustMember.do', {
		//	memberId: memberId
		//}, $(".m-repayment-loan")); //回款中
		//_this._ajaxGetResult(server_url + '/user/getCountRepaymentFinishBpCustMember.do', {
		//	memberId: memberId
		//}, $(".m-repayment-finish")); //已还完
		//_this._ajaxGetResult(server_url + '/user/getCountRepaymentFaildBpCustMember.do', {
		//	memberId: memberId
		//}, $(".m-repayment-faild")); //投标失败
	}
}